#include <stdio.h>
#include <stdlib.h>

//int* printNumbers(int n, int* returnSize) {
//    *returnSize = pow(10, n) - 1;
//    int* arr = (int*)malloc(sizeof(int) * (*returnSize));
//    for (int i = 0; i < *returnSize; i++)
//    {
//        arr[i] = i + 1;
//    }
//    return arr;
//}


int main()
{
    int a, b, c;
    while (scanf("%d %d %d", &a, &b, &c) != EOF)
    {
        if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0)
        {
            switch (b)
            {
            case 1:
                printf("%d", c);
                break;
            case 2:
            case 4:
            case 5:
                printf("%d", 30 * (b - 1) + c + 1);
                break;
            case 3:
                printf("%d", 30 * (b - 1) + c);
                break;
            case 6:
            case 7:
                printf("%d", 30 * (b - 1) + c + 2);
                break;
            case 8:
                printf("%d", 30 * (b - 1) + c + 3);
                break;
            case 9:
            case 10:
                printf("%d", 30 * (b - 1) + c + 4);
                break;
            case 11:
            case 12:
                printf("%d", 30 * (b - 1) + c + 5);
                break;
            }
        }
        else
        {
            switch (b)
            {
            case 1:
                printf("%d", c);
                break;
            case 2:
            case 6:
            case 7:
                printf("%d", 30 * (b - 1) + c + 1);
                break;
            case 3:
                printf("%d", 30 * (b - 1) + c - 1);
                break;
            case 4:
            case 5:
                printf("%d", 30 * (b - 1) + c);
                break;
            case 8:
                printf("%d", 30 * (b - 1) + c + 2);
                break;
            case 9:
            case 10:
                printf("%d", 30 * (b - 1) + c + 3);
                break;
            case 11:
            case 12:
                printf("%d", 30 * (b - 1) + c + 4);
                break;
            }
        }
    }

    return 0;
}